#include "index.h"

using namespace std;
using namespace easyWebServer;


void Index::_404()
{
    string context("<h1> 404 Not Find </h1>");
    m_response->setHead();
    m_response->add("Content-Length", to_string(context.size()));
    m_response->addContext(context);
}

// void Index::index()
// {
//     string context;
//     fstream in;
//     stringstream ss;
//     in.open("./index_.html", ios_base::in);
//     ss << in.rdbuf();
//     context = ss.str();
//     in.close();
//     m_response->insertPair("Content-Length", to_string(context.size()));
//     m_response->setContext(context, "200 OK");
// }

// void Index::pic()
// {
//     m_fileSystem->find(Singleton<Json>::getInstance()["root"].asString() + "/paiDaXing.jpg");
//     m_response->setFileFd(m_fileSystem->getFileFd());
//     m_response->insertPair("Content-Length", to_string(m_fileSystem->getFileSize()));
//     m_response->setContext("", "200 OK");   
// }

void Index::demoPage()
{
    m_response->setHead();
    std::fstream in("./Index/index.html", ios_base::in);
    stringstream ss;
    ss << in.rdbuf();
    std::string ctx = ss.str();
    m_response->add("Content-Length", to_string(ctx.size()));
    m_response->add("Content-Type", "text/html; charset=UTF-8");
    m_response->addContext(ctx);
    in.close();
}



